package com.training.java.core.homework02;

import java.util.Scanner;

public class UnitedStatesRegionDemo {

	public static void main(String[] args) {

		UnitedStatesRegions unitedstatesregions = new UnitedStatesRegions();

		boolean stateFound = false;
		int stateIndex = 0;

		Scanner input = new Scanner(System.in);
		System.out.println("Enter state code: ");
		String stateCode = input.next();
		input.close();

		for (int i = 0; i < unitedstatesregions.getStateCodesArray().length; i++) {

			if (unitedstatesregions.getStateCodesArray()[i].equals(stateCode)) {
				stateFound = true;
				stateIndex = i;
			}
		}

		if (!stateFound) {
			System.out.println("Invalid state code");
		} else {
			if (stateIndex >= 0 && stateIndex <= 10) {
				System.out.println("State "
						+ unitedstatesregions.getStatesArray()[stateIndex]
						+ "(" + stateCode + ")" + " is in region "
						+ unitedstatesregions.getRegionsArray()[0]);
			}
			if (stateIndex >= 11 && stateIndex <= 22) {
				System.out.println("State "
						+ unitedstatesregions.getStatesArray()[stateIndex]
						+ "(" + stateCode + ")" + " is in region "
						+ unitedstatesregions.getRegionsArray()[1]);
			}
			if (stateIndex >= 23 && stateIndex <= 34) {
				System.out.println("State "
						+ unitedstatesregions.getStatesArray()[stateIndex]
						+ "(" + stateCode + ")" + " is in region "
						+ unitedstatesregions.getRegionsArray()[2]);
			}
			if (stateIndex >= 35 && stateIndex <= 38) {
				System.out.println("State "
						+ unitedstatesregions.getStatesArray()[stateIndex]
						+ "(" + stateCode + ")" + " is in region "
						+ unitedstatesregions.getRegionsArray()[3]);
			}
			if (stateIndex >= 39 && stateIndex <= 49) {
				System.out.println("State "
						+ unitedstatesregions.getStatesArray()[stateIndex]
						+ "(" + stateCode + ")" + " is in region "
						+ unitedstatesregions.getRegionsArray()[4]);
			}
		}
	}
}
